import serial.tools.list_ports

def scan_serial_ports():
    """
    扫描系统中所有可用的串口并输出到控制台
    """
    print("正在扫描系统中的串口...")
    ports = list(serial.tools.list_ports.comports())
    
    if not ports:
        print("未找到可用的串口")
        return
    
    print(f"找到 {len(ports)} 个串口:")
    print("-" * 50)
    
    for i, port in enumerate(ports):
        print(f"{i+1}. 端口: {port.device}")
        print(f"   描述: {port.description}")
        print(f"   硬件ID: {port.hwid}")
        if port.vid:
            print(f"   VID: {hex(port.vid)}")
        if port.pid:
            print(f"   PID: {hex(port.pid)}")
        print("-" * 50)

if __name__ == "__main__":
    scan_serial_ports()